# -*- coding: utf-8 -*-
import redis
import configparser
import os
import sys

import django

from django.conf import settings

django.setup()

if getattr(sys, 'frozen', False):
    base_dir = os.path.dirname(sys.executable)
else:
    base_dir = settings.BASE_DIR
ini_path = os.path.join(base_dir, 'settings.ini')

config = configparser.ConfigParser()
config.read(ini_path)

queue_host = config.get('REDIS_QUEUE', 'host')
queue_port = config.get('REDIS_QUEUE', 'port')
queue_db = config.get('REDIS_QUEUE', 'db')
queue_password = config.get('REDIS_QUEUE', 'password')

websocket_redis_client = redis.StrictRedis(
    host=queue_host,
    port=int(queue_port),
    db=int(queue_db),
    password=queue_password
)

channels_host = config.get('REDIS_CHANNELS', 'host')
channels_port = config.get('REDIS_CHANNELS', 'port')
channels_db = config.get('REDIS_CHANNELS', 'db')
channels_password = config.get('REDIS_CHANNELS', 'password')

channels_redis_client = redis.StrictRedis(
    host=channels_host,
    port=int(channels_port),
    db=int(channels_db),
    password=channels_password
)

# websocket_redis_client = redis.StrictRedis(
#     host='47.106.36.163',
#     port=6379,
#     db=6,
#     password='swat@888'
# )
#
# channels_redis_client = redis.StrictRedis(
#     host='47.106.36.163',
#     port=6379,
#     db=7,
#     password='swat@888'
# )
